﻿using B.S.Data.MES.API.Applications.QualityManagement.ExamineProjectCommand.Commands;
using B.S.Domain.BasicData.QualityManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.QualityManagement.ExamineProjectCommand.CommandHandlers
{
    public class DeleteExamineProjectCommandHandler : IRequestHandler<DeleteExamineProjectCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<ExamineProject> _examineprojectRepository;
        public DeleteExamineProjectCommandHandler(IBaseRepository<ExamineProject> examineprojectRepository)
        {

            _examineprojectRepository = examineprojectRepository;
        }
        public Task<APIRequst<int>> Handle(DeleteExamineProjectCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> result = new APIRequst<int>();
            result.Code = RequstCode.成功;
            result.Msg = RequstCode.成功.ToString();

            var list=_examineprojectRepository.GetAll().FirstOrDefault(x=>x.ExamineProjectId==request.ExamineProjectId);

            list.isDel= true;
            list.DeleteName = request.DeleteName;
            list.DeleteTime = DateTime.Now;

            _examineprojectRepository.Update(list);

            return Task.FromResult(result);

        }
    }
}
